<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Map" %>
<%@ page import="net.sf.json.JSONObject" %>
<%@ page import="net.sf.json.JSONSerializer" %>

<%
   response.reset();
   response.setContentType("application/vnd.ms-excel;charset=GBK");
   response.setHeader("Content-disposition","attachment; filename=xtszxx.xls" );
%>

<html>
    <head>
	 	<%
		    String tableData = request.getParameter("tableData");
		    Object list1 = JSONSerializer.toJSON(tableData);
		    Map dataMap1 = (Map) list1;
		    List data = (List)dataMap1.get("rows");
		    
		    String columns = request.getParameter("tableColumns");
		    List columns1 = (List)JSONSerializer.toJSON(columns);
		    List columnList = (List)columns1.get(0);
		    String[] columnsArr = new String[columnList.size()];
		    for(int i = 0;i < columnList.size(); i++){
			    Map map = (Map)columnList.get(i);
			    columnsArr[i] = String.valueOf(map.get("field"));
		    }
	    %>
        <title>EXCEL</title>
	</head>
	
    <body>
    	<form name="fm" method="post" >
	       <table cellpadding="5" cellspacing="1"  align="center"  style="width: 100%;font-size: 9pt;style-align: center;background-color: #ffffff;border: 1px solid #cccccc;">
			   <tr>
				  <%
				  	for(int i = 1;i < columnList.size(); i++){
				    Map map =(Map)columnList.get(i);
				  %>
				   <td class=formtitle align="center" nowrap style="width:13%;font-size: 9pt;background:#a480b2;color:#ffffff;height:30px;text-align: center;border: 1px solid #cccccc;"><%=map.get("title") %></td>
				  <%
				  	} 
				  %>
			   </tr>
			   <%
			  	for(int j = 0;j < data.size(); j++){Map map =(Map)data.get(j);
			   %> 
			   <tr>
				   <%
				    for(int k = 1;k < columnsArr.length; k++){
				     String field = columnsArr[k];
				     String fieldValue=(map.get(field)==null)?"":""+map.get(field);
				     if( k == 2) {
				     	 if(fieldValue.startsWith("0")) {
				     	  	fieldValue="'"+fieldValue;
				     	 }
				     }
				   %>
				   <td class=formtitle2 align="left" nowrap style="width:13%;font-size: 9pt;background:#ffffff;color:#000000;height:30px;text-align: left;border: 1px solid #cccccc;class:text"><%=fieldValue==null?"":""+fieldValue %></td>
				   <%}%>
			   </tr>
			   <%} %>
	        </table>
     	 </form>
     </body>
</html>